<template>
  <div>
    <a-alert class="card"  message="※博士分数线设置和按学科专业码设置同时设置时，以最后设置的分数线为准，外语分数线设置为单项匹配。不需要设置分数线的项目，分数线请设置为0" banner />

    <a-card>
      <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="学术学位分数线设置" key="1" forceRender>
        <stu-info ref="stuInfo"></stu-info>
      </a-tab-pane>
      <a-tab-pane tab="专业学位分数线设置" key="2" forceRender>
        <scoreInfo ref="scoreInfo"/>
      </a-tab-pane>
    </a-tabs>
    </a-card>
  </div>
</template>
<script>
import { mapState } from 'vuex'
import stuInfo from './components/professional'
import scoreInfo from './components/professionalStu'

const selectArr = ['TYPE0320', 'TYPE0321', 'TYPE0011', 'TYPE0360', 'TYPE0342', 'TYPE0018', 'TYPE0023', 'TYPE0126']

export default {
  data () {
    return {
      selectMenu: {
        ml:[],
        xk:[]
      },
      loading: false,
      imageUrl: '',
      loadingBtn: false,
      queryParam:{
        'xk':'',
        'ml':'',
        'zy':''
      },
      xkdm:''
    }
  },
    components: {
    stuInfo,
    scoreInfo
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  computed: {
   ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let code='01';
      let parms={xklb:code}
      let allRequest = [
        this.$api.base.subjectAll(parms)
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          ml: res[0].data
        }
      })
      this.$api.base.getSchoolYear().then(res=>{
        this.form.setFieldsValue({'zsnj':res.data.doctoralAdmissionYear})
      })
    },
     mlChange (code) {
        console.log(code)
        // this.queryParam.xk='';
        // this.queryParam.zy='';
        this.form.setFieldsValue({'xkm':'','xkzym':''})
        this.$set(this.selectMenu,'xk','')
        this.$set(this.selectMenu,'zy','')
        if(code){
          this.xkdm=code;
        var ml = this.selectMenu.ml
				this.$api.base.subjectAll({
					fjxkdm: code
				}).then(res => {
					if (res.data) {
						this.selectMenu = {
							ml: ml,
              xk: res.data,
              zy:[]
						}
					}
        })
        }
    },
    xkChange(code){
         this.form.setFieldsValue({'xkzym':''})
         this.$set(this.selectMenu,'zy','')
         if(code){
           this.xkdm=code;
        var ml = this.selectMenu.ml;
        var xk = this.selectMenu.xk;
				this.$api.base.getDisline({
					xkdm: code
				}).then(res => {
					if (res.data) {
						this.selectMenu = {
							ml: ml,
              xk: xk,
              zy:res.data
						}
					}
        })
         }
    },
    zyChange(code){
        if(code){
          this.xkdm=code;
        }
    },
    handleSearch () {
    },
    handleSubmit () {
      this.form.validateFields((err, values) => {
          if (err) {
            this.$message.error('请输入必填项')
            return
          }
      // console.log(this.form.getFieldsValue())
      this.$api.doctorRecruit.majorSave(this.form.getFieldsValue()).then(res => {
         this.$message.success(res.msg)
          this.form.setFieldsValue({'xkmlm':'','xkm':'','xkzym':'','wytlfsx':'','wybsfsx':'','wykyfsx':'','wyzffsx':'','ywkyfsx':'','ywkefsx':'','ywksfsx':'','ywkzcjfsx':''})
           this.xkdm=''
      	// this.$emit('success')
      }).finally(() => {
      	this.loadingBtn = false

      })

    })
    }

  }
}
</script>
